﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;

namespace RecruitmentProcessSystem
{
    public partial class frmEditInterview : Form
    {
        String conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
        SqlConnection conn;
        SqlCommand cmd, cmd_add, cmd_edit;
        SqlDataAdapter da,da1,da2;
        DataSet ds,ds1,ds2;
        String iid,time,i,a,v,s;
        public frmEditInterview(String iid,String time,String i,String a, String v,String s)
        {
            InitializeComponent();
            this.iid = iid;
            this.time = time;
            this.i = i;
            this.a = a;
            this.v = v;
            this.s = s;
        }

        private void frmEditInterview_Load(object sender, EventArgs e)
        {
            dtpDatetime.Text = time;
            ds = new DataSet();
            conn = new SqlConnection(conStr);
            conn.Open();
            cmd = new SqlCommand("Select * from Nhanvien where not role = 'admin'", conn);
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Interviewer");
            cboInterviewer.DataSource = ds.Tables[0];
            cboInterviewer.DisplayMember = "tennv";
            cboInterviewer.Text = i;
            conn.Close();

            ds1 = new DataSet();
            conn = new SqlConnection(conStr);
            conn.Open();
            cmd_add = new SqlCommand("Select * from Applicant", conn);
            da1 = new SqlDataAdapter(cmd_add);
            da1.Fill(ds1, "Applicant---");
            cboApplicant.DataSource = ds1.Tables[0];
            cboApplicant.DisplayMember = "aname";
            cboApplicant.Text = a;
            conn.Close();

            ds2 = new DataSet();
            conn = new SqlConnection(conStr);
            conn.Open();
            cmd_edit = new SqlCommand("Select * from Vacancy", conn);
            da2 = new SqlDataAdapter(cmd_edit);
            da2.Fill(ds2, "Vacancy---");
            cboVacancy.DataSource = ds2.Tables[0];
            cboVacancy.DisplayMember = "vname";
            cboVacancy.Text = v;
            conn.Close();

            txtStatus.Text = s;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            conn = new SqlConnection(conStr);
            conn.Open();
            String time = dtpDatetime.Value.ToString();
            String interviewer = cboInterviewer.Text;
            String applicant = cboApplicant.Text;
            String vacancy = cboVacancy.Text;
            cmd_edit = new SqlCommand("update Interview set idate = '" + time + "',interviewer = '" + interviewer + "',aname = '" + applicant + "',vname = '" + vacancy + "',istatus = '" + txtStatus.Text + "' where iid = " +iid, conn);
            cmd_edit.ExecuteNonQuery();
            conn.Close();
            MessageBox.Show("Update successfully!");
            this.Hide();
            frmInterviewManager frm = new frmInterviewManager();
            frm.ShowDialog();
            this.Close();
        }
    }
}
